package com.yjx.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.yjx.service.CacheService;
import com.yjx.util.RedisUtil;
import com.yjx.vo.ParentResourceVo;

import javax.annotation.Resource;
import java.util.List;

public class CacheServiceImpl implements CacheService {
    @Resource
    private RedisUtil redisUtil;
    @Override
    public void saveResource(String key, List<ParentResourceVo> parentResourceVoList) {
        String resourceJson = JSONObject.toJSONString(parentResourceVoList);
        redisUtil.put(key,resourceJson);
    }

    @Override
    public List<ParentResourceVo> getResourceVoList(String key) {
        String resourceJson = redisUtil.get(key);
        List<ParentResourceVo> parentResourceVoList
                = JSONObject.parseArray(resourceJson,ParentResourceVo.class);
        return parentResourceVoList;
    }
}
